package com.emep.redis.springbootredis.controller;

import com.emep.redis.springbootredis.domian.User;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import sun.plugin2.util.SystemUtil;

/**
 * @author kalista
 * @version 1.0.0
 */
@RestController
@RequestMapping
public class UserController {
//
//    @CachePut(value = "user", key = "#root.caches[0].name + ':' + #user.userId")
//    @RequestMapping(value = "/redis/user", method = RequestMethod.POST)
//    public User insertUser(@RequestBody User user) {
//        user.setPassword(SystemUtil.MD5(user.getPassword()));
//        userService.insertSelective(user);
//        return user;
//    }
//
//    @Cacheable(value = "user")
//    @RequestMapping(value = "/redis/user/{userId}", method = RequestMethod.GET)
//    public User getUser(@PathVariable Integer userId) {
//        User user = userService.getUserById(userId);
//        return user;
//    }
//    //#root.caches[0].name:当前被调用方法所使用的Cache, 即"user"
//    @CachePut(value = "user", key = "#root.caches[0].name + ':' + #user.userId")
//    @RequestMapping(value = "/redis/user", method = RequestMethod.PUT)
//    public User updateUser(@RequestBody User user) {
//        user.setPassword(SystemUtil.MD5(user.getPassword()));
//        userService.updateByPrimaryKeySelective(user);
//        return user;
//    }
//
//    @CacheEvict(value = "user")
//    @RequestMapping(value = "/redis/user/{userId}", method = RequestMethod.DELETE)
//    public void deleteUser(@PathVariable Integer userId) {
//        userService.deleteByPrimaryKey(userId);
//    }
}
